package edu.utdallas.cs.securechat.ui;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.text.DefaultCaret;

public class TextPanel extends JPanel{
	private static final long serialVersionUID = 8295840933205050104L;
	private JTextArea text;
	private JScrollPane scroll;

	public TextPanel(){
		this.setLayout(new BorderLayout());
		text = new JTextArea();
		DefaultCaret caret = (DefaultCaret)text.getCaret();
		caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
		scroll = new JScrollPane(text);
		scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		text.setEditable(false);
		text.setLineWrap(true);
		this.add(scroll, BorderLayout.CENTER);
	}

	public void addText(String s){
		String writeText = "\n"+s;
		text.append(writeText);
	}
}
